package com.itheima.doudizhu1;

import java.math.RoundingMode;
import java.util.*;

public class PokerGame {
    //用于建立牌与顺序的关系，以便从小到大
    static HashMap<Integer,String>  hm=new HashMap<>();
    static  ArrayList<Integer> list=new ArrayList<>();
    //准备牌，借助静态代码块，随着类的加载而加载，只进行一次
    static{
        //花色
        //数字
        String[] color={"♠","♥","♣","♦"};

        String[] number={"3","4","5","6","7","8","9","10","J","Q","K","A","2"};

        //拼接
            int serialNumber=0;
        for (String n : number) {
            //针对每一种花色，都要实现数字的拼接
            for (String c : color) {
              hm.put(serialNumber,c+n);
              list.add(serialNumber);
              serialNumber++;
            }
        }
        //添加大小王
        hm.put(serialNumber,"小王");
        list.add(serialNumber) ;
         serialNumber++;
        hm.put(serialNumber,"大王");
        list.add(serialNumber);
      //  System.out.println(hm);
    }

    public PokerGame()
    {  //1.成功实现扑克牌的准备
       // System.out.println(list);

        //洗牌
        Collections.shuffle(list);
      //  System.out.println(list);

        //发牌  底牌，玩家1，玩家2，玩家3
       TreeSet<Integer> lord=new TreeSet<>();
       TreeSet<Integer> player1=new TreeSet<>();
       TreeSet<Integer> player2=new TreeSet<>();
       TreeSet<Integer> player3=new TreeSet<>();


        //遍历牌实现发放,本质是根据数字
        for (int i = 0; i < list.size(); i++) {
           int s = list.get(i);
            //先给地主的底牌发
            if(i<=2)
            {
                lord.add(s);
                continue;
            }

            //根据余数给剩下三个玩家发牌
            if(i%3==0)
            {
                player1.add(s);
            }
            else if(i%3==1)
            {
                player2.add(s);
            }else
            {
                player3.add(s);
            }
        }

        //看牌(写成一个方法)
        lookPuker("底牌",lord);
        lookPuker("玩家1",player1);
        lookPuker("玩家2",player2);
        lookPuker("玩家3",player3);
    }

    public void lookPuker(String name,TreeSet<Integer> list)
    {
        System.out.println(name+" :");
        for (int Poker : list) {
            String s = hm.get(Poker);
            System.out.print(s+" ");
        }
        System.out.println();
    }

}
